import React, { useState } from 'react'
import { View, Image, NativeModules } from 'react-native'
import { WingBlank, Flex, Button } from '@ant-design/react-native'

import myImagePicker from '../../components/my-image-picker'
import myLocation from '../../components/my-location'

export default function CommonFn() {
    const [img, setImg] = useState()

    function test() {
        const BGNativeModuleExample = NativeModules.BGNativeModuleExample
        // BGNativeModuleExample.testPrint('Jack', {
        //     height: '1.78m',
        //     weight: '7kg',
        // })
        BGNativeModuleExample.getNativeClass((name) => {
            console.log('nativeClass: ', name)
        })
    }

    return (
        <View>
            <WingBlank style={{ margin: 5 }}>
                <Flex>
                    <Flex.Item style={{ paddingLeft: 4, paddingRight: 4 }}>
                        <Button
                            size="small"
                            onPress={async () =>
                                await myImagePicker((v) => {
                                    console.log(v)
                                    setImg(v)
                                })
                            }
                        >
                            打开本地图片
                        </Button>
                    </Flex.Item>
                    <Flex.Item style={{ paddingLeft: 4, paddingRight: 4 }}>
                        <Button
                            size="small"
                            onPress={async () =>
                                await myLocation((v) => {
                                    console.log(v)
                                })
                            }
                        >
                            获取定位
                        </Button>
                    </Flex.Item>
                    <Flex.Item style={{ paddingLeft: 4, paddingRight: 4 }}>
                        <Button
                            size="small"
                            onPress={() => {
                                test()
                            }}
                        >
                            按钮3
                        </Button>
                    </Flex.Item>
                </Flex>
            </WingBlank>
            <Image
                style={{ width: 300, height: 300 }}
                resizeMode="contain"
                source={{
                    uri: img,
                }}
            />
        </View>
    )
}
